package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.InvoiceInfoBean;
import com.koron.css2.baseConfig.bean.ProjectPayeeBean;
import com.koron.css2.baseConfig.mapper.InvoiceInfoMapper;
import com.koron.css2.baseConfig.mapper.ProjectPayeeMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 工程收款主体 根据ID查找
 * @author lch
 *
 */
public class ProjectPayeeQuery implements ServerInterface{
	private static Logger log = LogManager.getLogger(ProjectPayeeSave.class);
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<ProjectPayeeBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", ProjectPayeeBean.class);

		try { 
			ProjectPayeeBean bean = JsonUtils.objectToPojo(req.getData(), ProjectPayeeBean.class);
			ProjectPayeeMapper mapper = factory.getMapper(ProjectPayeeMapper.class);
			InvoiceInfoMapper invoiceInfoMapper = factory.getMapper(InvoiceInfoMapper.class);
			ProjectPayeeBean projectPayee = mapper.query(bean);
			List<InvoiceInfoBean> invoiceInfoList = invoiceInfoMapper.selectByProjectPayeeId(projectPayee.getId());
			projectPayee.setInvoiceInfos(invoiceInfoList);
			info.setData( projectPayee);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			log.error(e.getMessage(), e);
		}
		return info;
	}

}
